﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using BUS;
using DTO;

namespace BCSALE
{
    public partial class frmMaTuDong : DevComponents.DotNetBar.Office2007Form
    {        
        public void initDataSource()
        {
            txtMaHangHoa.Text = MaTuDongBUS.layMA(LOAIMATUDONG.HANG_HOA);
            txtMaHangHoa.Tag = LOAIMATUDONG.HANG_HOA;
            
            txtMaKhachHang.Text = MaTuDongBUS.layMA(LOAIMATUDONG.KHACH_HANG);
            txtMaKhachHang.Tag = LOAIMATUDONG.KHACH_HANG;

            txtMaNhaCungCap.Text = MaTuDongBUS.layMA(LOAIMATUDONG.NHA_CUNG_CAP);
            txtMaNhaCungCap.Tag = LOAIMATUDONG.NHA_CUNG_CAP;

            txtMaPhieuChi.Text = MaTuDongBUS.layMA(LOAIMATUDONG.PHIEU_CHI);
            txtMaPhieuChi.Tag = LOAIMATUDONG.PHIEU_CHI;

            txtMaPhieuNhap.Text = MaTuDongBUS.layMA(LOAIMATUDONG.PHIEU_NHAP);
            txtMaPhieuNhap.Tag = LOAIMATUDONG.PHIEU_NHAP;

            txtMaPhieuThu.Text = MaTuDongBUS.layMA(LOAIMATUDONG.PHIEU_THU);
            txtMaPhieuThu.Tag = LOAIMATUDONG.PHIEU_THU;

            txtMaPhieuXuat.Text = MaTuDongBUS.layMA(LOAIMATUDONG.PHIEU_XUAT);
            txtMaPhieuXuat.Tag = LOAIMATUDONG.PHIEU_XUAT;
        }

        public frmMaTuDong()
        {
            InitializeComponent();
            initDataSource();            
        }

        private void kiemTraTrung(object sender, DevComponents.DotNetBar.Validator.ValidateValueEventArgs e)
        {            
            TextBoxX tb = e.ControlToValidate as TextBoxX;
                                    
            foreach (object o in this.panelMain.Controls)
            {
                if (o is TextBox)
                {
                    TextBoxX t = o as TextBoxX;
                    if (t.Name != tb.Name && t.Text.Trim() == tb.Text.Trim())
                    {                        
                        e.IsValid = false;
                    }
                }
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (MaTuDongBUS.capNhatMa(txtMaHangHoa.Text, LOAIMATUDONG.HANG_HOA) &&
               MaTuDongBUS.capNhatMa(txtMaKhachHang.Text, LOAIMATUDONG.KHACH_HANG) &&
               MaTuDongBUS.capNhatMa(txtMaNhaCungCap.Text, LOAIMATUDONG.NHA_CUNG_CAP) &&
               MaTuDongBUS.capNhatMa(txtMaPhieuChi.Text, LOAIMATUDONG.PHIEU_CHI) &&
               MaTuDongBUS.capNhatMa(txtMaPhieuNhap.Text, LOAIMATUDONG.PHIEU_NHAP) &&
               MaTuDongBUS.capNhatMa(txtMaPhieuThu.Text, LOAIMATUDONG.PHIEU_THU) &&
               MaTuDongBUS.capNhatMa(txtMaPhieuXuat.Text, LOAIMATUDONG.PHIEU_XUAT))
            {
                MessageBox.Show("Cập nhật thành công!");
            }
        }

        private void txtMaHangHoa_Leave(object sender, EventArgs e)
        {

        }
    }
}